package com.imooc.distributedemo.resume.leetcode;

/**
 * leetcode58 最后一个单词的长度
 */
public class Solution58 {
    public static void main(String[] args) {
        String s = "   fly me   to   the moon  ";
        int num = lengthOfLastWord(s);
        System.out.println(num);
    }

    public static int lengthOfLastWord(String s) {
        if(null == s || "".equals(s)){
            return 0;
        }
        String str = s.trim();
        int num = 0;
        for (int i = str.length()-1; i >=0;i--) {
            char ch = str.charAt(i);
            if(Character.isWhitespace(ch)){
                break;
            }
            num++;
        }
        return num;
    }
}
